package com.itheima.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.Service.OrderService;
import com.itheima.bean.Orders;
import com.itheima.common.R;
import com.itheima.dto.OrdersDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;
    /**
     * 订单表分页查询
     * @param page
     * @param pageSize
     * @return
     */
    @RequestMapping("/page")
    public R findPage(int page, int pageSize,Long number, @DateTimeFormat(pattern="yyyy-MM-dd HH:m:ss")Date beginTime,@DateTimeFormat(pattern ="yyyy-MM-dd HH:mm:ss") Date endTime){
/*        System.out.println("page = " + page);
        System.out.println("pageSize = " + pageSize);*/
        IPage<OrdersDto> dtoIPage = orderService.findPage(page, pageSize, number, beginTime, endTime);
        return R.success(dtoIPage);
    }

    @RequestMapping("/submit")
    public R submit(@RequestBody Orders orders){
//        System.out.println("submit = " + orders);
        int submit = orderService.submit(orders);
        if (submit==1){
            return R.success("下单成功");
        }
        return R.error("下单失败");
    }
}
